package com.zhs.smartmall.product.service.impl;


import com.zhs.smartmall.product.model.PmsCategoryBrandRelation;
import com.zhs.smartmall.product.dao.PmsCategoryBrandRelationDao;
import com.zhs.smartmall.product.service.IPmsCategoryBrandRelationService;
import com.zhs.smartmall.product.dto.PmsCategoryBrandRelationDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-11
 */
@Service
@Slf4j
public class PmsCategoryBrandRelationServiceImpl extends ServiceImpl< PmsCategoryBrandRelationDao, PmsCategoryBrandRelation> implements IPmsCategoryBrandRelationService {

    @Resource
    private PmsCategoryBrandRelationDao pmsCategoryBrandRelationDao;

    @Override
    @Transactional
    public R addOrUpdate(PmsCategoryBrandRelationDto pmsCategoryBrandRelationDto) {
        if (BeanUtil.isEmpty(pmsCategoryBrandRelationDto)) throw new ServiceException("数据不能为空");
        PmsCategoryBrandRelation pmsCategoryBrandRelation = new PmsCategoryBrandRelation();
        BeanUtil.copyProperties(pmsCategoryBrandRelationDto,pmsCategoryBrandRelation);
        if (pmsCategoryBrandRelationDto.getId() == null){
            pmsCategoryBrandRelationDao.insert(pmsCategoryBrandRelation);
            return R.ok("数据插入成功");
        }else {
            pmsCategoryBrandRelationDao.updateById(pmsCategoryBrandRelation);
            return R.ok("数据更新成功");
        }
    }
}